package com.heying.xmlandjson.jacksonjson;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.heying.xmlandjson.entity.User;

public class Userjson {

    public static void main(String[] args) throws JsonProcessingException {
        User user = new User("aaa","123");
        ObjectMapper objectMapper = new ObjectMapper();
        //序列化成json
        String json = objectMapper.writeValueAsString(user);
        System.out.println(json);

        //反序列化
        User user2 = objectMapper.readValue(json, User.class);
        System.out.println(user2);

    }
}
